package com.badlogic.androidgames.game;

import java.util.LinkedList;
import java.util.List;

import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Graphics;
import com.badlogic.androidgames.game.TouchObject.STATE;

import android.graphics.Rect;


public class TouchManager 
{
	private static TouchManager instance;
	
	static TouchManager getInstance()
	{
		if(instance == null)
		{
			instance = new TouchManager();
			LoaderButton();
		}
		return instance;
	}
	
	private static LinkedList<TouchObject> obj;
	
	public void Update(Game game)
	{
		for (int i = 0; i < obj.size(); i++) 
		{
			obj.get(i).Update(game);
		}
	}
	
	
	public void DrawObject(Graphics g, NAME_BUTTON nameButton)
	{
		for (int i = 0; i < obj.size(); i++) 
		{
			if(obj.get(i).nameButton == nameButton)
			{
				obj.get(i).Draw(g);
			}
		}
	}
	
	
	public boolean FirstTouch(NAME_BUTTON nameButton)
	{
		for (int i = 0; i < obj.size(); i++) 
		{
			if(obj.get(i).nameButton == nameButton)
			{
				if(obj.get(i).state == STATE.FIRST_TOUCH)
				{
					return true;
				}
				return false;
			}
		}
		//avisa que nao existe esse botao
		return false;
	}

	public boolean NotTouch(NAME_BUTTON nameButton)
	{
		for (int i = 0; i < obj.size(); i++) 
		{
			if(obj.get(i).nameButton == nameButton)
			{
				if(obj.get(i).state == STATE.NOT_TOUCH)
				{
					return true;
				}
				return false;
			}
		}
		//avisa que nao existe esse botao
		return false;
	}
	
	public boolean ContinuousTouch(NAME_BUTTON nameButton)
	{
		for (int i = 0; i < obj.size(); i++) 
		{
			if(obj.get(i).nameButton == nameButton)
			{
				if(obj.get(i).state == STATE.CONTINUOUS_TOUCH)
				{
					return true;
				}
				return false;
			}
		}
		return false;
	}
	
	
	public boolean UpTouch(NAME_BUTTON nameButton)
	{
		for (int i = 0; i < obj.size(); i++) 
		{
			if(obj.get(i).nameButton == nameButton)
			{
				if(obj.get(i).state == STATE.UP_TOUCH)
				{
					return true;
				}
				return false;
			}
		}
		return false;
	}
	
	private static void LoaderButton()
	{
		if(obj == null)
		{
			obj = new LinkedList<TouchObject>();
			obj.add(new TouchObject(Assets.Jump, new Vector2(10, 10), new Vector2(50,50), NAME_BUTTON.CIMA));
		}
	}
	
	static enum NAME_BUTTON
	{
		CIMA,
	}
}
